From d6f00427738906151a0f721217d49ce3b003503e Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 16 May 2011 20:20:55 +0200 Subject: [PATCH] css: Make _gtk_css_selector_matches() take a path length This will be necessary when handling inherit. --- gtk/gtkcssprovider.c | 4 ++-- gtk/gtkcssselector.c | 20 +++++++++++++++++--- gtk/gtkcssselectorprivate.h | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index 2cf49ad1f1..fd2696a32e 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -1123,7 +1123,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider, info = g_ptr_array_index (priv->selectors_info, i); - if (!_gtk_css_selector_matches (info->selector, path)) + if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path))) continue; g_hash_table_iter_init (&iter, info->style); @@ -1175,7 +1175,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider, info = g_ptr_array_index (priv->selectors_info, i); - if (!_gtk_css_selector_matches (info->selector, path)) + if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path))) continue; selector_state = _gtk_css_selector_get_state_flags (info->selector); diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c index 3850a9eaf4..35db9ca7ae 100644 --- a/gtk/gtkcssselector.c +++ b/gtk/gtkcssselector.c @@ -353,18 +353,32 @@ gtk_css_selector_matches_previous (const GtkCssSelector *selector, return FALSE; } +/** + * _gtk_css_selector_matches: + * @selector: the selector + * @path: the path to check + * @length: How many elements of the path are to be used + * + * Checks if the @selector matches the given @path. If @length is + * smaller than the number of elements in @path, it is assumed that + * only the first @length element of @path are valid and the rest + * does not exist. This is useful for doing parent matches for the + * 'inherit' keyword. + * + * Returns: %TRUE if the selector matches @path + **/ gboolean _gtk_css_selector_matches (const GtkCssSelector *selector, - /* const */ GtkWidgetPath *path) + /* const */ GtkWidgetPath *path, + guint length) { GSList *list; - guint length; gboolean match; g_return_val_if_fail (selector != NULL, FALSE); g_return_val_if_fail (path != NULL, FALSE); + g_return_val_if_fail (length <= gtk_widget_path_length (path), FALSE); - length = gtk_widget_path_length (path); if (length == 0) return FALSE; diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h index 70c5e600cf..5a158824d8 100644 --- a/gtk/gtkcssselectorprivate.h +++ b/gtk/gtkcssselectorprivate.h @@ -48,7 +48,8 @@ void _gtk_css_selector_print (const GtkCssSelector *sel GtkStateFlags _gtk_css_selector_get_state_flags (GtkCssSelector *selector); gboolean _gtk_css_selector_matches (const GtkCssSelector *selector, - /* const */ GtkWidgetPath *path); + /* const */ GtkWidgetPath *path, + guint length); int _gtk_css_selector_compare (const GtkCssSelector *a, const GtkCssSelector *b); -- 2.30.2